<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>黔南民族师范学院综合教育学分认定系统</title>

    <link rel="stylesheet" href="/jquery-easyui-1.3.5/themes/icon.css" />
    <link rel="stylesheet" href="/jquery-easyui-1.3.5/themes/default/easyui.css"/>

    <script type="text/javascript" src="/jquery-easyui-1.3.5/jquery.min.js"></script>
    <script type="text/javascript" src="/jquery-easyui-1.3.5/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/jquery-easyui-1.3.5/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" th:inline="none">
        $(function(){
            $('#dg').datagrid({
                url:'/role/queryAllRoles',
                striped:true,
                idField:'roleId',
                fitColumn:true,
                nowrap:true,
                pagination:true,
                pageSize:10,
                pageList:[10,15,20,25],
                toolbar: [

                    {
                        iconCls: 'icon-add',
                        text:'添加角色',
                        handler: function(){
                            parent.$("#win").window({
                                title:"添加角色信息",
                                width:400,
                                height:200,
                                content:'<iframe src="/role/save" frameborder="0" width="100%" height="100%">'
                            });
                        }
                    },
                    '-',
                    {
                        iconCls: 'icon-edit',
                        text:'更新角色',
                        handler: function(){
                            var row = $("#dg").datagrid("getSelections");
                            if(row.length != 1){
                                $.messager.show({
                                    title:'错误提示',
                                    msg:'请选择一条记录',
                                    timeout:5000,
                                    showType:'slide'
                                });
                            }else{
                                parent.$("#win").window({
                                    title:"更新角色",
                                    width:400,
                                    height:200,
                                    content:'<iframe src="/role/update" frameborder="0" width="100%" height="100%">'
                                });
                            }
                        }
                    },'-',{
                        iconCls: 'icon-remove',
                        text:'删除角色',
                        handler: function(){
                            var rows = $("#dg").datagrid("getSelections");
                            if(rows.length != 1){
                                $.messager.show({
                                    title:'错误提示',
                                    msg:'请选择一条记录',
                                    timeout:5000,
                                    showType:'slide'
                                });
                            }else{
                                $.messager.confirm('删除确认对话框', '是否要删除选中的记录?', function(r){
                                    if (r){
                                        var ids = "";
                                        for(var i=0;i<rows.length;i++){
                                            ids+=rows[i].roleId + ",";
                                        }
                                        ids=ids.substring(0, ids.lastIndexOf(","));
                                        $.post("/role/roleDelete",{ids:ids},function(result){
                                            if(result=="ok"){
                                                $("#dg").datagrid("reload");
                                                $("#dg").datagrid("uncheckAll");
                                            }else{
                                                $.messager.show({
                                                    title:'删除异常',
                                                    msg:'无法删除,角色已关联用户!',
                                                    timeout:2000,
                                                    showType:'slide'
                                                });
                                            }
                                        });
                                    }
                                });
                            }
                        }
                    },'-',

                    {
                        iconCls: 'icon-ok',
                        text:'设置权限',
                        handler: function(){
                            var rows = $("#dg").datagrid("getSelections");
                            if(rows.length != 1){
                                $.messager.show({
                                    title:'错误提示',
                                    msg:'请选择一条记录',
                                    timeout:5000,
                                    showType:'slide'
                                });
                            }else{
                                parent.$("#win").window({
                                    title:"设置权限",
                                    width:400,
                                    height:400,
                                    content:'<iframe src="/role/setPermission" frameborder="0" width="100%" height="100%">'
                                });
                            }
                        }
                    }

                ],

                columns:[[
                    {field:'check',checkbox:true},
                    {field:'roleId',title:'编号',width:100,align:'center'},
                    {field:'roleName',title:'角色名称',width:200,align:'center'}
                ]]
            });

        });
    </script>
</head>

<body>
<table id="dg"></table>
</body>
</html>
